package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.MarketDataDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.MarketData;
import sanrenxing.dayEnd.backRepertoryTotal.domain.MarketDataT;
import sanrenxing.dayEnd.backRepertoryTotal.service.MarketDataService;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @desrciption 行情数据 业务处理
 * @auth：yidu 李小锋
 * @date:2021/3/13 0013 - 16:02
 * @version:1:0
 */
@Service("MarketDataService")
public class MarketDataServiceImpl implements MarketDataService {
    //自动装配
    @Autowired
    private MarketDataDao marketDataDao;
    /**
     * 新增一行数据
     *
     * @param marketData 对象
     * @return 0、增加失败 1、增加成功
     */
    @Override
    public int add(MarketData marketData) {
        return marketDataDao.add(marketData);
    }

    /**
     * 删除一行数据
     *
     * @param marketId 编号
     * @return 0、删除失败 1、删除成功
     */
    @Override
    public int delete(int marketId) {
        return marketDataDao.delete(marketId);
    }

    /**
     * 修改一行数据
     *
     * @param marketData 对象
     * @return 0、修改失败 1、修改成功
     */
    @Override
    public int update(MarketData marketData) {
        return marketDataDao.update(marketData);
    }

    /**
     * 查询所有的订单数据
     *
     * @return 返回一个订单集合
     */
    @Override
    public List<MarketData> findAll() {
        return marketDataDao.findAll();
    }

    /**
     * 分页查询
     *
     * @param start     开始行号
     * @param rows      每页行数
     * @param condition 查询条件
     * @return 集合
     */
    @Override
    public List<MarketData> findByPage(int start, int rows, String condition) {
        int pages=((rows-1)*start)+1;
        return marketDataDao.findByPage(pages,start+pages,condition);
    }

    /**
     * 按条件统计出记录行数
     *
     * @param condition 条件
     * @return 记录行数
     */
    @Override
    public int count(String condition) {
        return marketDataDao.count(condition);
    }

    /**
     * 获取查询条件
     *
     * @param marketData 对象
     * @return 条件字符串
     */
    @Override
    public String getcondition(MarketData marketData) {


        String condition= " ";
        if(marketData==null){
            return condition;
        }
        //id	主键编号	int
        if(marketData.getMarketId()!=0){
            condition+="and MarketId '%"+marketData.getMarketId()+"%'";
        }
        //seId	证券编号	varchar2
        if (marketData.getSeId()!=null && marketData.getSeId().trim().length()!=0){
            condition+="and seId  like '%"+marketData.getSeId()+"%'";
        }
        //inputDate	录入日期	date
        if(marketData.getInputDate()!=null){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            condition+="and inputDate=to_date('"+sdf.format(marketData.getInputDate())+"','yyyy-MM-dd')+1";
        }
        //openPrice	开盘价格	number
        if(marketData.getOpenPrice()!=0){
            condition+="and openPrice '%"+marketData.getOpenPrice()+"%'";
        }
        //closePrice	闭市价格	number
        if(marketData.getClosePrice()!=0){
            condition+="and closePrice '%"+marketData.getClosePrice()+"%'";
        }
        //notes	备注	varchar2
        if (marketData.getNotes()!=null && marketData.getNotes().trim().length()!=0){
            condition+="and notes like '%"+marketData.getNotes()+"%'";
        }
        return condition;
    }

    @Override
    public void exclMethod(MarketDataT marketDataT) {
        marketDataDao.addExcl(marketDataT);
    }
}
